home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Sprite 1984 - 1993
/
Sprite 1984 - 1993.iso
/
src
/
lib
/
c
/
unixSyscall
/
RCS
/
gethostname.c,v
< prev
next >
Wrap
Text File
|
1992-06-16
|
4KB
|
212 lines
head 1.5;
branch ;
access ;
symbols ;
locks ; strict;
comment @ * @;
1.5
date 92.06.16.11.20.59; author jhh; state Exp;
branches ;
next 1.4;
1.4
date 89.10.16.14.34.26; author douglis; state Exp;
branches ;
next 1.3;
1.3
date 89.09.12.11.49.48; author jhh; state Exp;
branches ;
next 1.2;
1.2
date 88.06.30.17.28.47; author ouster; state Exp;
branches ;
next 1.1;
1.1
date 88.06.19.14.31.24; author ouster; state Exp;
branches ;
next ;
desc
@@
1.5
log
@now uses system call to get host name
@
text
@/*
* gethostname.c --
*
* Procedure to simulate Unix gethostname system call.
*
* Copyright 1986 Regents of the University of California
* All rights reserved.
*/
#ifndef lint
static char rcsid[] = "$Header: /sprite/src/lib/c/unixSyscall/RCS/gethostname.c,v 1.4 89/10/16 14:34:26 douglis Exp Locker: jhh $ SPRITE (Berkeley)";
#endif not lint
#include <host.h>
#include <string.h>
#include <sys.h>
#include <sys/param.h>
#include <status.h>
#include "compatInt.h"
/*
*----------------------------------------------------------------------
*
* gethostname --
*
* Puts the host name into the the given buffer.
*
* Results:
* 0 is returned if the call was completed successfully.
* Otherwise, -1 is returned and errno gives more information.
*
* Side effects:
* The name buffer is modified.
*
*----------------------------------------------------------------------
*/
int
gethostname(name, nameLen)
char *name; /* Place to store name. */
int nameLen; /* Length of name buffer. */
{
char tmp[MAXHOSTNAMELEN];
ReturnStatus status;
Host_Entry *entry;
int localID;
/*
* Try using the new system call. If that doesn't work then do it
* the old way. Strip out the old way once all kernels have the
* system call -- jhh
*/
status = Sys_GetHostName(tmp);
if (status == SYS_INVALID_SYSTEM_CALL) {
status = Proc_GetHostIDs(&localID, (int *) NULL);
if (status != SUCCESS) {
errno = Compat_MapCode(status);
return UNIX_ERROR;
}
entry = Host_ByID(localID);
if (entry == (Host_Entry *) NULL) {
Host_End();
return UNIX_ERROR;
}
strncpy(name, entry->name, nameLen-1);
name[nameLen-1] = 0;
Host_End();
} else if (status != SUCCESS) {
errno = Compat_MapCode(status);
return UNIX_ERROR;
} else {
strncpy(name, tmp, nameLen);
}
return 0;
}
@
1.4
log
@return virtual host (home node) rather than physical
@
text
@d11 1
a11 1
static char rcsid[] = "$Header: /sprite/src/lib/c/unixSyscall/RCS/gethostname.c,v 1.3 89/09/12 11:49:48 jhh Exp Locker: douglis $ SPRITE (Berkeley)";
d17 2
d44 3
a47 1
ReturnStatus status;
d49 5
d55 7
a61 5
status = Proc_GetHostIDs(&localID, (int *) NULL);
if (status != SUCCESS) {
errno = Compat_MapCode(status);
return UNIX_ERROR;
}
d63 7
a69 2
entry = Host_ByID(localID);
if (entry == (Host_Entry *) NULL) {
d71 2
d74 2
a76 3
strncpy(name, entry->name, nameLen-1);
name[nameLen-1] = 0;
Host_End();
@
1.3
log
@uses Proc_GetHostIDs
@
text
@d11 1
a11 1
static char rcsid[] = "$Header: /sprite/src/lib/c/unixSyscall/RCS/gethostname.c,v 1.2 88/06/30 17:28:47 ouster Exp Locker: jhh $ SPRITE (Berkeley)";
d46 1
a46 1
status = Proc_GetHostIDs((int *) NULL, &localID);
@
1.2
log
@Update to use new Host_ package.
@
text
@d11 1
a11 1
static char rcsid[] = "$Header: gethostname.c,v 1.1 88/06/19 14:31:24 ouster Exp $ SPRITE (Berkeley)";
d46 1
a46 1
status = Sys_GetMachineInfo((int *) NULL, (int *) NULL, &localID);
@
1.1
log
@Initial revision
@
text
@d11 1
a11 1
static char rcsid[] = "$Header: gethostname.c,v 1.2 87/08/06 13:30:36 andrew Exp $ SPRITE (Berkeley)";
d14 3
a16 2
#include <errno.h>
#include "sprite.h"
a17 1
#include "sys.h"
d28 2
a29 2
* UNIX_SUCCESS if the call returned SUCCESS
* UNIX_ERROR, errno=EINVAL if the call failed.
d42 19
a60 5
if (Sys_GetHostName(nameLen, name) != SUCCESS) {
errno = EINVAL;
return(UNIX_ERROR);
}
return(UNIX_SUCCESS);
@